package com.icehand.learn.graphql.resolver;

import com.coxautodev.graphql.tools.GraphQLMutationResolver;
import com.icehand.learn.graphql.domain.Author;
import com.icehand.learn.graphql.mapper.AuthorMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
@AllArgsConstructor
public class Mutation implements GraphQLMutationResolver {
	private final AuthorMapper authorMapper;

	public Author newAuthor(String firstName,String lastName) {
		Author author = new Author()
			.setFirstName(firstName)
			.setLastName(lastName)
			.setCreateTime(new Date());
		authorMapper.insert(author);
		return author;
	}
}
